package pacs_server

import (
	"fmt"
	"gitee.com/uni-minds/bridge-pacs/tools"
)

func (pi *PacsServer) ExportInstances(studiesIds []string) (err error) {
	total := len(studiesIds)
	for i, studies_id := range studiesIds {
		fmt.Printf("parse %d/%d, studies_id: %s ", i, total, studies_id)
		studies_info, err := pi.FindStudiesByIdLocal(studies_id)
		if err != nil {
			fmt.Println("E1:", err.Error())
			continue
		} else {
			fmt.Println()
		}

		for _, series_id := range tools.IdStrDecodeString(studies_info.IncludeSeries) {
			fmt.Printf("- series_id: %s ", series_id)
			series_info, err := pi.FindSeriesByIdLocal(series_id)
			if err != nil {
				fmt.Println("E2:", err.Error())
				continue
			} else {
				fmt.Println("memo:", series_info.LabelMemo)
			}

			for _, instance_id := range tools.IdStrDecodeString(series_info.IncludeInstances) {

				instance_info, err := pi.FindInstanceByIdLocal(instance_id)
				if err != nil {
					fmt.Println("E3:", err.Error())
					continue
				}

				if instance_info.DbHidden != 0 || instance_info.DbDelete != 0 {
					continue
				} else if instance_info.LabelView == "" || instance_info.LabelView == "无效切面" {
					continue
				} else {
					fmt.Printf("v=%s,f=%d,u=%s\n", instance_info.LabelView, instance_info.Frames, instance_info.URL)
				}
			}
		}

	}
	return nil
}
